<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 -->
<!-- 
* @desc:日志分页公共组件
* @fileName:LogsPagination.vue
* @author:chenxiaofeng@yzbdl.ac.cn
* @date:2022-4-7
!-->
<script setup lang="ts">
import { ref } from "vue";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
const props = defineProps({
  // 当前分页页面传递
  getCurrentPageNumber: Function,
  // 每页显示条数
  pageSize: {
    type: Number,
    default: 10,
  },
  // 总数
  total: {
    type: Number,
    default: 100,
  },
});
// 选中页数
const currentPage = ref(1);

//定义中文zh-cn
const locale = zhCn;

/**
 * 改变每页条数方法
 * @param pageNumber 每页显示条数
 * @reture viod
 */
const handleSizeChange = (pageNumber: number) => {
  console.log(`${pageNumber} items per page`);
};

/**
 * 选中页码方法
 * @param pageNumber 每页显示条数
 * @reture viod
 */
const handleCurrentChange = (pageNumber: number) => {
  props.getCurrentPageNumber?.(pageNumber);
};
</script>

<template>
  <!-- 分页 -->
  <div class="page-pagination">
    <el-config-provider :locale="locale">
      <el-pagination
        v-model:currentPage="currentPage"
        background
        :page-size="props.pageSize"
        layout="prev, pager, next, total"
        :total="props.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        prev-text="上一页"
        next-text="下一页"
      />
    </el-config-provider>
  </div>
</template>

<style scoped lang="scss">
.page-pagination {
  margin-top: 15px;
  display: flex;
  justify-content: end;
  :deep(.number) {
    padding: 0 !important;
    background-color: unset !important;
  }
  :deep(.btn-prev) {
    color: #000;
    padding: 0 10px;
    background-color: #f2f2f6 !important;
    border-radius: 2px;
  }
  :deep(.btn-next) {
    color: #000;
    background-color: #f2f2f6 !important;
    border-radius: 2px;
    padding: 0 10px;
  }
  :deep(.el-pagination__total) {
    margin-left: 10px;
  }
  :deep(.more) {
    background-color: unset !important;
  }
}
:deep(.number.is-active) {
  background-color: #5473e6 !important;
}
</style>
